#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

int semid;

int main()
{
	key_t key = ftok(".",100);
	semid = semget(key , 0  , 0 );
	
	int i = 0 ;
	for( ; i < 10 ; ++i)
	{
		pid_t pid = fork();
		if(pid == 0)
		{
			struct sembuf op;
			op.sem_num = 0;
			op.sem_op = -1;
			op.sem_flg = 0;
			semop(semid , &op , 1);
			printf("apply for resource.\n");
			sleep(10);
			printf("over.\n");
			op.sem_op = 1;
			semop(semid , &op , 1);
			exit(0);
		}
	}
	return 0;
}
